package com.example.demo;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.time.Duration;

public class unittesting {
    @Test
    public  void  test01ArrayAssertions(){
        Assertions.assertArrayEquals(
                new int[]{777,888},
                new int[]{777,888},
                "你瞎眼了,这肯定测试不过"
        );
    }

    @DisplayName("组合断言")
    @Test
    public void testAssertAll(){
        Assertions.assertAll(
                "测试组合判断",
                ()->Assertions.assertEquals("suncat","suncat"),
                ()->Assertions.assertTrue(true)
        );
    }

    @Test
    public  void  test02assertYichang(){
        //代码有异常就抛出,判断代码是否能够执行成功
        Assertions.assertThrows(
                // 预期代码有问题
                RuntimeException.class,
                // 实际上 10/10  代码没有问题
                // 实际上 10/0   代码有问题
                ()->System.out.println(10/0)
        );
    }

    @DisplayName("超时断言")
    @Test
    public void testTimeout(){
        Assertions.assertTimeout(
                Duration.ofMillis(6000),
                ()->Thread.sleep(2000)
        );
    }
}
